package com.bs.bookshare.controller;


import com.bs.bookshare.Mapper.BookMapper;
import com.bs.bookshare.common.Resp;
import com.bs.bookshare.request.requestAuthorname;
import com.bs.bookshare.request.requestBookname;
import com.bs.bookshare.request.requestCurrentPage;
import com.bs.bookshare.request.requestGetbooks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import static com.bs.bookshare.common.Resp.ok;

@RestController
public class BookAction {

    @Autowired
    public BookMapper book;

    // 根据页码返回书籍信息
    @PostMapping("/getBooksinfo")
    public Resp getBooksinfo(@RequestBody requestGetbooks currentPage) {
        System.out.println(currentPage.getCurrentPage());
        return ok().data("bookinfo",book.selectBooksBylimit(currentPage.getCurrentPage()));
    }

    @PostMapping("/getBooksBybookname")
    public Resp getBooksinfoBybookname(@RequestBody requestBookname bookname) {
        System.out.println(bookname.getBookname());
        return ok().data("bookinfo",book.selectBooksBybookname(bookname.getBookname()));
    }

    @PostMapping("/getBooksByauthorname")
    public Resp getBooksinfoByauthorname(@RequestBody requestAuthorname authorname) {
        System.out.println(authorname.getAuthorname());
        return ok().data("bookinfo",book.selectBooksByauthorname(authorname.getAuthorname()));
    }
}
